home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’93 / Jon’s FKEYs / FKEYList ƒ / FKEYList FKEY.p < prev    next >
Text File  |  1992-09-28  |  4KB  |  181 lines

  1. {    FKEYList FKEY © 1992 by Jon Wind                                                            }
  2. {    Version 1.0 on 9/28/92                                                                        }
  3.  
  4. {    This FKEY lets you draw a rectangle on the screen and displays it's coordinates.        }
  5.  
  6. {     Thanks to Brad Pettit and his colorfkey for his method of conditional compilation.    }
  7.  
  8. {    To execute this as a program...                                                                }
  9. {        1. change the definition of fkey to false                                                    }
  10. {        2. set the project type to application                                                    }
  11. {        3. change the library from drvrruntime.lib to µruntime.lib                            }
  12. {        4. rebuild the project}
  13.  
  14.  
  15. {$setc fkey := true}
  16.  
  17. {$ifc fkey}
  18.  
  19. unit FKEYList;
  20.  
  21. interface
  22.  
  23.     procedure main;
  24.  
  25. implementation
  26.  
  27. {$elsec}
  28.  
  29.     program FKEYList;
  30.  
  31. {$endc}
  32.  
  33.         procedure main;
  34.             const
  35.                 kCredits = 'FKEYList 1.0 by Jon Wind';
  36.                 kFont = 'Chicago';
  37.                 kRezType = 'FKEY';
  38.                 kWidth = 380;
  39.                 kNameCol = 34;
  40.                 kIDCol = 264;
  41.                 kIDCol_15 = 249;
  42.                 kNameTitle = 'Name';
  43.                 kIDTitle = 'Command Key';
  44.                 kNoFKEYsMsg = 'No FKEYs installed';
  45.             type
  46.                 FKEYrec = record
  47.                         ID: Integer;
  48.                         Name: StringHandle;
  49.                     end;
  50.                 FKEYArray = array[1..1] of FKEYrec;
  51.                 FKEYArrayPtr = ^FKEYArray;
  52.                 FKEYArrayHandle = ^FKEYArrayPtr;
  53.             var
  54.                 theWindow: WindowPtr;
  55.                 winRect: Rect;
  56.                 savePort: GrafPtr;
  57.                 p: grafport;
  58.                 theEvent: EventRecord;
  59.                 done: Boolean;
  60.                 i, theFont, iCnt, rezID, j, minIndx, row: Integer;
  61.                 rezType: resType;
  62.                 rezName: Str255;
  63.                 numStr: string[7];
  64.                 rezHdl: Handle;
  65.                 FKEYs: FKEYArrayHandle;
  66.                 tempFKEY: FKEYrec;
  67.  
  68.  
  69.             function aNum2Str (aNum: LongInt): Str255;
  70.     { NumToString procedure available as a function }
  71.                 var
  72.                     NumStr: Str255;
  73.             begin
  74.                 NumToString(aNum, NumStr);
  75.                 aNum2Str := NumStr;
  76.             end;
  77.  
  78.  
  79.  { --------- Main Procedure --------- }
  80.         begin
  81.             GetPort(savePort);            { save current grafport }
  82.  
  83.             iCnt := CountResources(kRezType);
  84.             FKEYs := FKEYArrayHandle(NewHandle(sizeof(FKEYArray) * iCnt));
  85.             MoveHHi(Handle(FKEYs));
  86.             HLock(Handle(FKEYs));
  87.  
  88.             SetRect(winRect, 0, 0, kWidth, 60 + (iCnt * 16));
  89.             if iCnt = 0 then
  90.                 winRect.bottom := winRect.bottom + 16;
  91.             OpenPort(@p);
  92.             OffsetRect(winRect, (p.portRect.right - winRect.right) div 2, (p.portRect.bottom - winRect.bottom) div 3);
  93.             ClosePort(@p);
  94.  
  95. {$push}
  96. {$r-}
  97.             SetResLoad(False);
  98.             for i := 1 to iCnt do
  99.                 begin
  100.                     rezHdl := GetIndResource(kRezType, i);
  101.                     GetResInfo(rezHdl, FKEYs^^[i].ID, rezType, rezName);
  102.                     if Length(rezName) = 0 then
  103.                         rezName := '[Untitled]';
  104.                     FKEYs^^[i].Name := NewString(rezName);
  105.                     SetString(FKEYs^^[i].Name, rezName);
  106.                 end;
  107.             SetResLoad(True);
  108.  
  109.             for i := 1 to iCnt do        { sort array using selection sort method }
  110.                 begin
  111.                     minIndx := i;
  112.                     for j := i + 1 to iCnt do
  113.                         if FKEYs^^[j].ID < FKEYs^^[minIndx].ID then
  114.                             minIndx := j;
  115.  
  116.                     tempFKEY := FKEYs^^[i];
  117.                     FKEYs^^[i] := FKEYs^^[minIndx];
  118.                     FKEYs^^[minIndx] := tempFKEY;
  119.                 end;
  120. {$pop}
  121.  
  122.             theWindow := NewWindow(nil, winRect, '', True, altDBoxProc, Pointer(-1), False, 0);
  123.             SetPort(theWindow);
  124.             GetFNum(kFont, theFont);
  125.             TextFont(theFont);
  126.             TextFace([underline]);
  127.             Moveto(kNameCol, 20);
  128.             DrawString(kNameTitle);
  129.             Moveto(kIDCol_15, 20);
  130.             DrawString(kIDTitle);
  131.             TextFace([]);
  132.  
  133. {$push}
  134. {$r-}
  135.             if iCnt > 0 then
  136.                 for i := 1 to iCnt do
  137.                     begin
  138.                         rezID := FKEYs^^[i].ID;
  139.                         numStr := aNum2Str(rezID);
  140.                         row := 26 + (i * 16);
  141.                         Moveto(kNameCol, row);
  142.                         DrawString(FKEYs^^[i].Name^^);
  143.                         Moveto(kIDCol, row);
  144.                         if (rezID >= 0) and (rezID <= 9) then
  145.                             DrawString(Concat('-Shift-', numStr))
  146.                         else
  147.                             DrawString(Concat('N/A [#', numStr, ']'));
  148.  
  149.                         DisposHandle(Handle(FKEYs^^[i].Name));
  150.                     end
  151.             else
  152.                 begin
  153.                     Moveto(kNameCol, 42);    {26 + 16}
  154.                     DrawString(kNoFKEYsMsg);
  155.                 end;
  156. {$pop}
  157.  
  158.             Moveto((kWidth - StringWidth(kCredits)) div 2, theWindow^.portRect.bottom - 8);
  159.             DrawString(kCredits);
  160.  
  161.             HUnlock(Handle(FKEYs));
  162.             DisposHandle(Handle(FKEYs));
  163.  
  164.             repeat
  165.             until GetOSEvent(mDownMask + keyDownMask, theEvent);{everyEvent}
  166.  
  167.             DisposeWindow(theWindow);
  168.  
  169. {•   InitCursor;•}
  170.             SetPort(savePort);            { restore grafport }
  171.         end;    { main }
  172.  
  173.  
  174. {$ifc fkey = false}
  175.  
  176.     begin
  177.         main;
  178.  
  179. {$endc}
  180.  
  181.     end.